package dk.dashboardFP.panels.loggerPanel {
	import dk.dashboardFP.dfpLogger.DFPLogger;
	import dk.dashboardFP.dfpLogger.LogGroup;
	import dk.dashboardFP.elements.checkBox.CheckBoxElement;
	import dk.dashboardFP.interactionElementFramwork.inputElement.CheckBoxEvent;
	import dk.dashboardFP.interactionElementFramwork.smartButton.SmartButtonEvent;
	import dk.dashboardFP.shapes.Circle;

	/**
	 * @author josef
	 */
	public class LogFilterItem extends CheckBoxElement {
		private var _oLogGroup : LogGroup;
		private var _doCirc : Circle;
		private var _levelFilterUI : LevelFilterUI;
		private var _windowWidth : Number;

		public function LogFilterItem(oLogGroup:LogGroup) {
			_oLogGroup = oLogGroup;
			super(oLogGroup.name);
			
			//:::::::
			// register 
			oCB.addEventListener(CheckBoxEvent.REQUEST_VALUE_CHANGE, onValueChangeRequest, false, 0, true);
		}

		override protected function setupElements() : void {
			super.setupElements();
			
			//:::::::
			// title 
			_doTitle.x+=10;
			
			//:::::::
			// blob 
			_doCirc=new Circle(3, _oLogGroup.color);
			addChild(_doCirc);
			
			_doCirc.x=27;
			_doCirc.y=8;
			
			// sectionName 
			_levelFilterUI=new LevelFilterUI();
			addChild(_levelFilterUI);
			
			_levelFilterUI.y=8;
			
			// register 
			addEventListener(SmartButtonEvent.CLICKED, onSmartButtonClicked, false, 0, true);
		}

		private function onSmartButtonClicked(event : SmartButtonEvent) : void {
			if (event.target is LevelButton) {
				dispatchEvent(new LogFilterItemEvent(LogFilterItemEvent.LEVEL_CHANGE, event.oRefrenceObject));
			}
		}

		public function get windowWidth() : Number { 
			return _windowWidth; 
		}
		
		public function set windowWidth(oNewValue:Number) : void { 
			_windowWidth=oNewValue;
			_levelFilterUI.x = oNewValue-49.5;
		}
		
		public function set logLevel(oNewValue:int) : void { 
			_levelFilterUI.selectLevel(oNewValue);
		}
		
		private function onValueChangeRequest(event : CheckBoxEvent) : void {
			dispatchEvent(new LogFilterItemEvent(LogFilterItemEvent.REQUEST_CHANGE));
		}

		public function get oLogGroup() : LogGroup {
			return _oLogGroup;
		}
	}
}
